pandas timeseries
pandas contains extensive capabilities and features for working with time series data for all domains. Tutorials
resample()
interpolate()
IEM :: ASOS/AWOS Network
code:python
today="20211026"
Tips
multiple columns to datetime
code:python
df.index=pd.to_datetime(df.year.astype(str)+df.month.astype(str) +df.day.astype(str)+df"hour:min",format="%Y%m%d%H:%M") Set the date column as the index
code:python
pd.read_csv('foo.csv', index_col='date',parse_dates=True)
code:python
read_csv('foo.csv', parse_dates='Date', index_col='Date') code:python
df = df.set_index("date")
code:python
df.set_index("date",inplace=True)
Calculating
Calculating daily standard deviation
code:pyhon
import pandas as pd
import numpy as np
# Sample data creation (assuming hourly data over multiple days)
dates = pd.date_range('2023-01-01', periods=72, freq='H')
data = np.random.rand(72) # Replace with your actual data
df = pd.DataFrame(data, index=dates, columns='Value') # Calculate daily standard deviation
daily_std = df.groupby(pd.Grouper(freq='D')).std()
Plot
code:python
ax = df.plot(color='red', figsize=(8, 5), linewidth=1, fontsize=12)
annotate
vertical line
code:python
ax.axvline("1939-01-01", color="red", linestyle='--')
vertical span
code:python
ax.axvspan('2004-07-01', '2005-08-31', color="red", alpha=0.5)
plotting tabels
color
colormaps argument
code:python
df.plot(colormap='cubehelix')
subplots
Subplots
Using layout and targeting multiple axes
Sea also